package dev.ece.suit.utils;

import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import dev.ece.util.tools.Constants;

public class ShaderFunctions {

	private static final Map<String, String> functions = new LinkedHashMap<String, String>();
	
	static {
		ClassLoader classLoader = ShaderFunctions.class.getClassLoader();
		addFunction("fog", classLoader.getResourceAsStream("functions/fog.func"));
		addFunction("function", classLoader.getResourceAsStream("functions/function.func"));
		addFunction("light", classLoader.getResourceAsStream("functions/light.func"));
		addFunction("material", classLoader.getResourceAsStream("functions/material.func"));
		addFunction("prepare", classLoader.getResourceAsStream("functions/prepare.func"));
		addFunction("model3d", classLoader.getResourceAsStream("functions/model3d.func"));
		addFunction("shadow", classLoader.getResourceAsStream("functions/shadow.func"));
		addFunction("deferlight", classLoader.getResourceAsStream("functions/deferlight.func"));
	}
	
	public static void addFunction(String key, InputStream is) {
		functions.put(StringUtils.join("${", key, "}"), Constants.loadStringSource(is).toString());
	}
	
	public static void addFunction(String key, String function) {
		functions.put(StringUtils.join("${", key, "}"), function);
	}
	
	public static void removeFunction(String key) {
		functions.remove(StringUtils.join("${", key, "}"));
	}
	
	public static Map<String, String> getFunctions() {
		return functions;
	}
	
}
